/*
 * client.c
 *
 *  Created on: 2012-5-14
 *      Author: ncrd
 */


#define SHM_MODE 0600

#include "../apue.h"
#include <sys/shm.h>

int main (void) {
	int shmid;
	int *ptr, *shmptr;
	key_t shmkey;

	shmkey = ftok("1.c", 0);
	if ((shmid = shmget(shmkey, 0, SHM_MODE)) < 0) err_sys("shmget error");
	if ((shmptr = (int *)shmat(shmid, 0, 0)) == (int *)-1) err_sys("shmat error");
	while (1) {
		sleep(1);
		printf("client before change: %d\n", *shmptr);
		*shmptr = 200;
	}
	if (shmdt(shmptr) < 0) err_sys("shmdt error");
	if (shmctl(shmid, IPC_RMID, NULL) < 0) err_sys("shmctl error");

	exit(0);
}
